package Review;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Wukong
 * Date: 2022-06-04
 * Time: 15:37
 */
class AgeComparator implements Comparator<Student>{


    @Override
    public int compare(Student o1, Student o2) {
        return o1.score-o2.score;
    }
}
class NameComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

public class StudentT  {
     public String name;
    public int score;


    public StudentT(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    public static void main(String[] args) {
        Student student=new Student("lisa",20);
        Student student1=new Student("lusi",19);
        AgeComparator ageComparator=new AgeComparator();
        int ret=ageComparator.compare(student,student1);

        NameComparator nameComparator=new NameComparator();
        Student[] students=new Student[3];
        students[0]=new Student("kong",20);
        students[1]=new Student("wu",15);
        students[2]=new Student("sun",23);
        Arrays.sort(students,new NameComparator());
        //Arrays.sort(students,new AgeComparator());
        System.out.println(Arrays.toString(students));

    }



}

